package com.example.zjx8969.myapplication;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;
import android.util.Log;

public class BaseLifeCycleObserver implements LifecycleObserver {
    LifecycleOwner owner;

    public BaseLifeCycleObserver(LifecycleOwner owner) {
        this.owner = owner;
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    private void method0() {
        logInfo();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    private void method1() {
        logInfo();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    private void method2() {
        logInfo();
    }

    private void logInfo() {
        if (owner == null) {
            return;
        }
        Log.e(owner.getClass().getSimpleName(), owner.getLifecycle().getCurrentState().name() +
                ":" + owner.getLifecycle().getCurrentState().ordinal());
    }
}
